import { getToken, removeToken, removeUsername } from "@api/app"
import router from "@router"
import store from "@store"

const whiteRouter = ['/login']

router.beforeEach((to, from, next) => {

    // token验证，如果getToken得到值，就跳转，如果没有就不跳转
    if (getToken()) {
        if (to.path === '/login') {
            removeToken()
            removeUsername()
            store.commit('app/setToken', '')
            store.commit('app/setUsername', '')
            next()
        } else {
            next()
        }
    } else {
        if (whiteRouter.indexOf(to.path) !== -1) {
            next()
        } else {
            next('/login')
        }
    }
    // next()
})